package com.zhp.common;

import lombok.Data;
import lombok.experimental.Accessors;
import org.springframework.http.HttpStatus;

/**
 * @author zhanghp
 * @since 2024/5/16 17:51
 */
@Data
@Accessors(chain = true)
@SuppressWarnings("all")
public class R<T> {

    private int code;

    private String msg;

    private T data;

    public static R success() {
        return new R().setCode(HttpStatus.OK.value()).setMsg("success");
    }

    public static <T> R<T> success(T data) {
        return new R().setCode(HttpStatus.OK.value()).setMsg("success").setData(data);
    }

    public static R fail() {
        return new R().setCode(HttpStatus.INTERNAL_SERVER_ERROR.value()).setMsg("fail");
    }

    public static <T> R fail(String msg) {
        return new R().setCode(HttpStatus.INTERNAL_SERVER_ERROR.value()).setMsg(msg);
    }

    public static <T> R fail(int code, String msg) {
        return new R().setCode(code).setMsg(msg);
    }

}
